package com.study.d015propertybind.jdk;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
*@description 使用JDK自带的属性绑定类PropertyChangeSupport
*@author xtayhame
*date 2020年3月4日
*version
*since v1.0
*/
public class PropertyChangeSupportTest {
		public static void main(String[] args) {
			Student s = new Student();
			s.setName("张三");
			s.setAge(18);
			s.support.addPropertyChangeListener(new PropertyChangeListener() {
				@Override
				public void propertyChange(PropertyChangeEvent evt) {
					System.out.println("old="+evt.getOldValue());
					System.out.println("new="+evt.getNewValue());
					System.out.println("name="+evt.getPropertyName());

				}
			});

			s.support.addPropertyChangeListener("proper_age", new PropertyChangeListener() {

				@Override
				public void propertyChange(PropertyChangeEvent evt) {
					System.out.println("proper_age old="+evt.getOldValue());
					System.out.println("proper_age new="+evt.getNewValue());
					System.out.println("proper_age name="+evt.getPropertyName());

				}
			});

			s.support.addPropertyChangeListener("proper_name", new PropertyChangeListener() {

				@Override
				public void propertyChange(PropertyChangeEvent evt) {
					System.out.println("proper_name old="+evt.getOldValue());
					System.out.println("proper_name new="+evt.getNewValue());
					System.out.println("proper_name name="+evt.getPropertyName());

				}
			});

			s.setName("张三2");
			s.setAge(30);

		}
}
